import { Component, OnInit, ViewChild, ɵɵsetComponentScope } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { SFComponent, SFSchema, SFSelectWidgetSchema, SFTextareaWidgetSchema, SFUISchema } from '@delon/form';
import { _HttpClient } from '@delon/theme';
import { NzModalService } from 'ng-zorro-antd/modal';
import { OrderManagementService } from '../../services/order-management.service';
// import { RiskOrderService } from '../../services/risk-order.service';
// import { CtcAppealComponent } from '../appeal/appeal.component';

@Component({
  selector: 'app-oder-management-component-risk-detail',
  templateUrl: './risk-detail.component.html',
  styleUrls: ['./risk-detail.component.less']
})
export class OrderManagementRiskDetailComponent implements OnInit {
  @ViewChild('sf', { static: false }) sf!: SFComponent;
  ui: SFUISchema = {};
  schema: SFSchema = {};
  // abnormalReason = [
  //   '司机装货轨迹异常',
  //   '司机卸货轨迹异常',
  //   '车辆装货轨迹异常',
  //   '司机位置未移动，或运输途中未打开APP',
  //   '运单轨迹严重异常'
  // ]
  i: any;
  logList: any = [];
  id: string = '';
  constructor(private modal: NzModalService, public service: OrderManagementService, public ar: ActivatedRoute) {
    this.id = this.ar.snapshot.params.id;
  }

  ngOnInit(): void {
    if (this.id) {
      this.getDetail(this.id);
      this.initSF();
    }

  }
  initSF() {
    this.schema = {
      properties: {
        representationsCauseLabel: {
          title: '申诉原因',
          type: 'string',
          maxLength: 30,
          ui: {
            widget: 'text',
            change: (value, orgData) => console.log(value, orgData),
          } as SFSelectWidgetSchema,
        },
        representationsDescribe: {
          title: '申诉描述',
          type: 'string',
          ui: {
            widget: 'textarea',
            placeholder: '请输入',
            autosize: {
              minRows: 4,
              maxRows: 4
            }
          },

          readOnly: true

        } as SFTextareaWidgetSchema,
        uploadVanchor: {
          type: 'string',
          title: '上传凭证',
          ui: {
            widget: 'custom'
          }
        },
      },
    };

    this.ui = {
      '*': {
        spanLabelFixed: 100,
        grid: { span: 18 },
      },
      $uploadVanchor: {
        spanLabelFixed: 100,
        grid: { span: 24 },
      },
      $representationsDescribe: {
        grid: { span: 24 },
      }
    };
  }
  /**
 * 获取详情
 * @param id
 */
  getDetail(id: string) {
    this.service.request(this.service.$api_get_getRiskDetail, { id }).subscribe(res => {
      if (res) {
        this.i = Object.assign({}, res);
        console.log(this.i);
        let list: any = [];
        this.i.fileArr.map((item: any, index: number) => {
          const obj = {
            uid: index,
            name: '文件' + (index + 1),
            status: 'done',
            url: item,
          };
          list.push(obj);
        });
        this.i.uploadVanchor = list;
        this.initSF();
        this.getLog(this.i?.billCode);
      }
    })
  }
  // getDetail(id: string) {

  //   this.service.request(this.service.$api_get_getRiskDetail, { id }).subscribe(res => {
  //     if (res) {
  //       this.i = res;
  //     }
  //   })
  // }

  edit(item: any): void {
    const modalRef = this.modal.create({
      nzTitle: '申诉',
      nzWidth: '40%',
      // nzContent: CtcAppealComponent,
      nzComponentParams: {
        i: item
      },
      nzFooter: null
    });
    modalRef.afterClose.subscribe(res => {
      if (res) {

      }
    })
  }
  goBack() {
    window.history.go(-1)
  }
  /**
    * 获取操作日志
    */
  getLog(operateObject: any) {
    this.service.request(this.service.$api_get_risk_order_log, { operateObject, operateType: '8', size: 100 }).subscribe(res => {
      this.logList = res?.records;
    })
  }
}
